/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package communication;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import java.util.logging.Level;
import java.util.logging.Logger;




/**
 * Modified handler to get vents from a bluetooth connection. tu use this, one may have to Override methods handleEmpty, handleDistChange or handleSlopeChange
 * @author isen
 */
public class IncomingHandler extends Handler {
    
    /**
     * Used to signal there was an error parsing a message
     */
    static final int PARSE_ERROR = -1;
    /**
     * Flag for empty messages (or msg.what = 0)
     */
    public static final int EMPTY_MSG = 0;
    /**
     * flag for messages that signal changes of distance
     */
    public static final int INCOMING_BT_MSG = 1;
    /**
     * flag for messages that signal changes in the slope value
     */
    public static final int SEND_MESSAGE = 2;
    
    
    
    public static final int RESET = 3;
    
    public static final int RECONNECTED = 4;
    
    public static final int EXIT = 5;
    
    /**
     *  
     */
    int  distance;
    
    
    /**
     *  method which handle incomming messages and send them to the right method to commute them.
     * @param msg
     */
    @Override
    public void handleMessage(Message msg) {
        
        switch (msg.what) {
            
            case EXIT : 
                Log.i("incomingHandler", "received command to exit");
                break;
            case RECONNECTED:
                handleReconnect();
                
                break;
   
            case EMPTY_MSG:    
                handleEmpty();
                break;
                
            case INCOMING_BT_MSG:
                String content = (String)msg.obj;
                
                if (content.startsWith("movement:"))handleMoveChange(content.substring(9));
                
                if (content.startsWith("transmitData."))handleData(content.substring(13));
                break;
            case SEND_MESSAGE:
               
                handleSendMsg((String)msg.obj);
                break; 
                
            case RESET:
                handleReset();
                
                
                break;
            default:
                super.handleMessage(msg);
        }

    }
    
    
    /**
     * 
     */
    public void handleEmpty(){
        
    }
    /**
     * 
     * @param msg
     */
    public void handleMoveChange(String msg){
        
    }
    
    public void handleReconnect(){
        
    }

    /**
     * 
     * @param string
     */
    public void handleSendMsg(String string){
        
    }

    public void handleReset(){
        
    }

    public void handleData(String substring){
        
    }
    
}